package com.wsg.lightaccounting.Adapter;

import android.content.Context;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.wsg.lightaccounting.Model.ExpenditureType;
import com.wsg.lightaccounting.Model.RecordManager;
import com.wsg.lightaccounting.Model.SquareLayout;
import com.wsg.lightaccounting.R;

import java.util.LinkedList;
import java.util.List;

/**
 * Created by dell-pc on 2016/11/17.
 */

public class ExpenditureTypeGridAdapter extends BaseAdapter {
    private List<ExpenditureType> icons = new LinkedList<ExpenditureType>();
    private LayoutInflater layoutInflater;
    private Context context;


    public ExpenditureTypeGridAdapter(Context baseContext, List<ExpenditureType> expenditureTypes) {
        this.icons = expenditureTypes;
        this.context = baseContext;
        layoutInflater = LayoutInflater.from(context);
    }


    @Override
    public int getCount() {
        return icons.size();
    }

    @Override
    public Object getItem(int position) {
        return icons.get(position);
    }

    @Override
    public long getItemId(int position) {
        return icons.get(position).getId();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ItemViewTag viewTag;

            if (convertView == null) {
                convertView = layoutInflater.inflate(R.layout.gridview_layout, null);
                viewTag = new ItemViewTag((ImageView) convertView.findViewById(R.id.grid_icon), (TextView) convertView.findViewById(R.id.grid_name));
                convertView.setTag(viewTag);
            }
            else{
                viewTag = (ItemViewTag)convertView.getTag();
            }
                viewTag.mName.setText(icons.get(position).getName());
//                switch (icons.get(position).getIcon()) {
//                    case 0:
//                        viewTag.mIcon.setBackgroundResource(R.mipmap.accept);
//                        break;
//                    case 1:
//                        viewTag.mIcon.setBackgroundResource(R.mipmap.cash1);
//                        break;
//                    case 2:
//                        viewTag.mIcon.setBackgroundResource(R.drawable.btn_style_five_focused);
//                        break;
//                    default:
//                        break;
//                }
        RecordManager.getRecordManager(context).setIcon(viewTag.mIcon,true,icons.get(position).getIcon());
        if (!icons.get(position).is_show())
        {
            convertView.setVisibility(View.GONE);
        }
        return convertView;
    }

    class ItemViewTag {
        protected ImageView mIcon;
        protected TextView mName;

        public ItemViewTag(ImageView icon, TextView name) {
            this.mName = name;
            this.mIcon = icon;
        }
    }
}
